/**
 * zmn配件模块-配件列表
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author DaiZhichao
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function () {
    window.$ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let table = layui.table;
    let laytpl = layui.laytpl;
    let laypage = layui.laypage;
    let layedit = layui.layedit;
    let laydate = layui.laydate;
    let cols = [
        [
            {type: 'checkbox', width: 50, align: 'center'},
            // {type: 'numbers', title: '序号', width: 40, align: 'center'},
            {field: 'mapId', title: 'ID', width: 80, align: 'center'},
            {field: 'baseCategName', title: '产品一级分类', align: 'center'},
            {field: 'categName', title: '配件一级分类', align: 'center', sort: true},
            {field: 'creater', title: '创建人', width: 80, align: 'center', sort: true},
            {field: 'createTime', title: '创建时间', width: 150, align: 'center', templet: '<div>{{zmnUtil.createTime(d.createTime)}}</div>'}
        ]
    ];
    let ids = [];
    let tableRender = function tableRender(data) {
        zmnLayUtil.layTableRender(table, cols, "zmn-part-category-map-table", data, "/part/category/map/ajax/list.action");
    };
    let tableReload = function () {
        table.reload("zmn-part-category-map-table");
    };

    tableRender();

    //监听表单提交
    form.on('submit(query-submit)', function (data) {
        zmnMothedUtil.deleteEmptyProperty(data.field);
        tableRender(data.field);
        return false;
    });

    //【表格上方工具栏监听】
    table.on("toolbar(zmn-part-category-map-table)", function (obj) {
        if (obj.event === "add") {
            zmnLayUtil.openIframeCustom(layer, "/part/category/map/addEdit.action", {area: ["400px", "340px"], title: "添加关联"});

            // laytpl($('#zmn-part-category-map-edit').html()).render({}, function(html){
            //     layer.open({
            //         type: 1
            //         ,content:html
            //         ,title :'我是标题',
            //         success: function (layero) {
            //             $(layero).find('form').addClass('layui-form');
            //             form.render('select', 'zmn-purchase-apply-form');
            //         }
            //     });
            //
            // })
        } else if (obj.event === "delBatch") {
            let ids = table.checkStatus('zmn-part-category-map-table').data.map((item) => item.mapId);
            if (ids.length < 1) {
                layer.msg('请选择要删除的分类关联', {icon: 2});
                return;
            }
            layer.confirm('确定要删除已选中的关联吗?', {icon: 3}, function (index) {
                zmnLayUtil.ajaxResultDTOUE(layer, "/part/category/map/ajax/delete.action", {ids: ids}, 0, function () {
                    tableReload();
                });
                layer.close(index);
            });
        }
        return false;
    });


});